package controller;

import pojo.PageBean;
import pojo.User;
import service.AdminService;
import service.impl.AdminServiceimpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author LiangHaiBo
 * @version 1.0
 * @date 2021.9.8 下午 13:22
 */
@WebServlet("/findUserByPage")
public class AdminFindUserByPage extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        //1)接收前台的参数,如果没有参数,给它判断设置初始化值
        //当前页码
        String curPage = request.getParameter("currentPage");
        //分页条数
        String pSize = request.getParameter("pageSize");

        if(curPage == null || curPage.equals("")){
            curPage = "1" ; //当前页码
        }

        if(pSize == null || pSize.equals("")){
            pSize ="4" ; //每页显示两条
        }


        int currentPage = Integer.parseInt(curPage);
        int pageSize = Integer.parseInt(pSize);

        //调用业务方法
        AdminService adminService = new AdminServiceimpl();
        PageBean<User> pd = adminService.getUserByPage(currentPage, pageSize);

        request.setAttribute("pd",pd);

        request.getRequestDispatcher("admin/user_list.jsp").forward(request,response);

    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request,response);
    }
}
